new Vue({
    el: "#main",
    data: {
        // 控制页面大小及其右上角用户名
        user: {
            userName: "user",
            role: "游客",
            id:""
        },
        main_style: "height: 1000px; border: 1px solid rgb(17, 18, 21)",
        isUpdate:true,
        updateForm: {}, //修改表单数据
    },
    methods: {
        autodivheight() {
            //获取浏览器窗口高度
            var winHeight = 0;
            if (window.innerHeight)
                winHeight = window.innerHeight;
            else if ((document.body) && (document.body.clientHeight))
                winHeight = document.body.clientHeight;
            //通过深入Document内部对body进行检测，获取浏览器窗口高度
            if (document.documentElement && document.documentElement.clientHeight)
                winHeight = document.documentElement.clientHeight;
            //DIV高度为浏览器窗口的高度
            console.log(winHeight)
            setTimeout(() => {
                this.main_style = "height:" + winHeight + "px;" + " border: 1px solid rgb(17, 18, 21)"
            }, 1000)


            // document.getElementByClassName("main_test").style.height = winHeight + "px";
            console.log()
            //DIV高度为浏览器窗口高度的一半
            //document.getElementById("test").style.height= winHeight/2 +"px";
        },
        getUserRole(){
            //获取用户权限角色
            axios.get("/user/get/now").then(
                res=>{
                    if(res.data.code==='200'){
                        this.user.userName = res.data.data.name
                        this.user.role = res.data.data.role
                        this.user.id = res.data.data.id
                        this.get()
                    }else{
                        this.$message.error("请登录....")
                        window.setTimeout(()=>{
                            window.location.href="/index.html"
                        },1000)
                    }

                }
            )
        },
        logout(){
            axios.post("/user/logout").then(
                res=>{
                    if(res.data.code==='200'){
                        this.$message.success("登出成功")
                        window.setTimeout(()=>{
                            window.location.href="/index.html"
                        },1000)
                    }else{
                        this.$message.error("登出失败....")
                    }
                }
            )
        },
        handleUpdate(){
          this.isUpdate = false
        },
        get(){
          axios.get("/user/get/"+this.user.id).then(
              res=>{
                  if(res.data.code==='200'){
                      this.updateForm = res.data.data
                      // console.log(this.updateForm)
                  }else{
                      this.$message.error("请登录....")
                      window.setTimeout(()=>{
                          window.location.href="/index.html"
                      },1000)
                  }
              }
          )
        },
        update() {
            axios.put("/user/update", this.updateForm).then(
                res => {
                    this.dialogUpdateVisible = false
                    // console.log(res.data)
                    if (res.data.code === '200') {
                        this.$message.success("修改成功")
                        this.isUpdate = true

                        if(this.updateForm.password!=""){
                            this.$message.error("用户信息已变更，请重新登录！")

                            window.setTimeout(()=>{
                                this.logout()
                            },2000)

                        }
                    } else {
                        this.message.error("修改失败")
                    }

                }
            )
        },

    },
    created() {
        // window.alert("欢迎光临")
        this.getUserRole()
    },
    mounted() {
        this.autodivheight();
    }
})